home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / pdevtest / printStats.c.old < prev    next >
Text File  |  1989-10-21  |  23KB  |  641 lines

  1. /*
  2.  * printStats.c --
  3.  *    Routines to print out program execution times, and filesystem stats.
  4.  */
  5.  
  6. #include "sprite.h"
  7. #include "status.h"
  8. #include "stdio.h"
  9. #include "proc.h"
  10. #include "vm.h"
  11. #include "kernel/fs.h"
  12. #include "kernel/fsStat.h"
  13. #include "kernel/sched.h"
  14. #include "kernel/vm.h"
  15.  
  16.  
  17.  
  18. /*
  19.  *----------------------------------------------------------------------
  20.  *
  21.  * PrintTimes --
  22.  *
  23.  *    Print the resource usage (user and kernel CPU time) and elapsed time.
  24.  *
  25.  * Results:
  26.  *    None.
  27.  *
  28.  * Side effects:
  29.  *    Prints to the specified stream
  30.  *
  31.  *----------------------------------------------------------------------
  32.  */
  33. void
  34. PrintTimes(stream, usagePtr, timePtr)
  35.     FILE *stream;
  36.     Proc_ResUsage *usagePtr;
  37.     Time *timePtr;
  38. {
  39.     Time delta;
  40.     if (usagePtr != NULL) {
  41.     Time_Add(usagePtr->userCpuUsage, usagePtr->childUserCpuUsage,
  42.                      &delta);
  43.     fprintf(stream, "%d.%03du ", delta.seconds,
  44.                    delta.microseconds / 1000);
  45.     Time_Add(usagePtr->kernelCpuUsage, usagePtr->childKernelCpuUsage,
  46.                      &delta);
  47.     fprintf(stream, "%d.%03ds ", delta.seconds,
  48.                    delta.microseconds / 1000);
  49.     }
  50.     if (timePtr != NULL) {
  51.     int seconds = timePtr->seconds;
  52.     if (seconds >= 3600) {
  53.         fprintf(stream, "%d:", seconds / 3600);
  54.         seconds = seconds % 3600;
  55.     }
  56.     if (seconds >= 60) {
  57.         fprintf(stream, "%d:", seconds / 60);
  58.         seconds = seconds % 60;
  59.     }
  60.     fprintf(stream, "%d.%03d", seconds,
  61.                    timePtr->microseconds / 1000);
  62.     }
  63.     fprintf(stream, "\n");
  64. }
  65.  
  66.  
  67. /*
  68.  *----------------------------------------------------------------------
  69.  *
  70.  * PrintIdleTime --
  71.  *
  72.  *    Given two samples sched module statistics, this computes
  73.  *    the differenc in idle ticks and, using the time, computes
  74.  *    a utilization.
  75.  *
  76.  * Results:
  77.  *    None.
  78.  *
  79.  * Side effects:
  80.  *    Prints to the specified stream
  81.  *
  82.  *----------------------------------------------------------------------
  83.  */
  84. void
  85. PrintIdleTime(stream, startSchedPtr, endSchedPtr, timePtr)
  86.     FILE *stream;
  87.     Sched_Instrument *startSchedPtr, *endSchedPtr;
  88.     Time *timePtr;
  89. {
  90.     register     highTicks;
  91.     double     lowTicks;
  92.  
  93.     Sched_Instrument zeroStats;
  94.     if (startSchedPtr == NULL) {
  95.     Byte_Zero(sizeof(Sched_Instrument), &zeroStats);
  96.     startSchedPtr = &zeroStats;
  97.     }
  98.     highTicks = endSchedPtr->idleTicksOverflow -
  99.         startSchedPtr->idleTicksOverflow;
  100.     lowTicks = endSchedPtr->idleTicksLow - startSchedPtr->idleTicksLow;
  101.  
  102.     if (highTicks != 0) {
  103.     fprintf(stream, "(High ticks = %d)", highTicks);
  104.     }
  105.     if (timePtr->seconds == 0 && timePtr->microseconds == 0) {
  106.     fprintf(stream, "Idle ticks --/-- = 100%% Idle, Elapsed time ");
  107.     } else {
  108.     lowTicks /= 
  109.       (double)timePtr->seconds + (double) (timePtr->microseconds)*1000000.;
  110.     fprintf(stream, "Idle ticks %0.0f/%d = %6.2f%% Idle, Context Sw. %d inv %d full %d, Elapsed time ",
  111.            lowTicks,
  112.            endSchedPtr->idleTicksPerSecond,
  113.            (double)lowTicks/(double)endSchedPtr->idleTicksPerSecond * 100.,
  114.            endSchedPtr->numContextSwitches - startSchedPtr->numContextSwitches,
  115.            endSchedPtr->numInvoluntarySwitches - startSchedPtr->numInvoluntarySwitches,
  116.            endSchedPtr->numFullCS - startSchedPtr->numFullCS);
  117.     }
  118.     PrintTimes(stream, (Proc_ResUsage *)0, timePtr);
  119. }
  120.  
  121.  
  122. /*
  123.  *----------------------------------------------------------------------
  124.  *
  125.  * PrintFsStats --
  126.  *
  127.  *    Print out the filesystem statistics.  If both a start and end
  128.  *    sample of the statistics are given then the differences between
  129.  *    the two are printed.  To just print the total cumulative statistics
  130.  *    from one sample, specify a single FsStats buffer with the 'end'
  131.  *    parameter.
  132.  *
  133.  * Results:
  134.  *    None.
  135.  *
  136.  * Side effects:
  137.  *    Prints to the specified stream
  138.  *
  139.  *----------------------------------------------------------------------
  140.  */
  141. void
  142. PrintFsStats(stream, start, end, verbose)
  143.     FILE *stream;    /* Output stream */
  144.     FsStats *start;    /* 0, or address of "before run" statistics */
  145.     FsStats *end;    /* End of run statistics */
  146.     int verbose;    /* If true, everything is dumped */
  147. {
  148.     register int t1, t2, t3, t4, t5;
  149.     FsStats zeroStats;
  150.  
  151.     if (start == (FsStats *)0) {
  152.     bzero(&zeroStats, sizeof(FsStats));
  153.     start = &zeroStats;
  154.     }
  155.     /*
  156.      * Print cache size
  157.      */
  158.     fprintf(stream, "Cache blocks max %d min %d number %d/%d free %d/%d limit %d\n",
  159.                end->blockCache.maxCacheBlocks,
  160.                end->blockCache.minCacheBlocks,
  161.                start->blockCache.numCacheBlocks,
  162.                end->blockCache.numCacheBlocks,
  163.                start->blockCache.numFreeBlocks,
  164.                end->blockCache.numFreeBlocks,
  165.                end->blockCache.maxNumBlocks);
  166.  
  167.     /*
  168.      * Print bytes read traffic ratio
  169.      */
  170.     t1 = end->blockCache.bytesRead - start->blockCache.bytesRead;
  171.     t2 = end->blockCache.dirBytesRead - start->blockCache.dirBytesRead;
  172.     t3 = end->gen.remoteBytesRead - start->gen.remoteBytesRead;
  173.     t4 = end->gen.fileBytesRead - start->gen.fileBytesRead;
  174.     t5 = end->gen.physBytesRead - start->gen.physBytesRead;
  175.     fprintf(stream, "Bytes read %d+%d remote %d disk %d+%d",
  176.                t1, t2, t3, t4, t5);
  177.     if (t1 + t2 > 0) {
  178.     fprintf(stream, "\ttraffic ratio %%%d\n",
  179.                (int)((double)(t3+t4+t5)/(double)(t1+t2) * 100.));
  180.     } else {
  181.     fprintf(stream, "\n");
  182.     }
  183.  
  184.     /*
  185.      * Print bytes written traffic ratio
  186.      */
  187.     t1 = end->blockCache.bytesWritten - start->blockCache.bytesWritten +
  188.     (end->blockCache.fileDescWrites - start->blockCache.fileDescWrites +
  189.      end->blockCache.indBlockWrites - start->blockCache.indBlockWrites) *
  190.     FS_BLOCK_SIZE;
  191.     t2 = end->blockCache.dirBytesWritten - start->blockCache.dirBytesWritten;
  192.     t3 = end->gen.remoteBytesWritten - start->gen.remoteBytesWritten;
  193.     t4 = end->gen.fileBytesWritten - start->gen.fileBytesWritten;
  194.     t5 = end->gen.physBytesWritten - start->gen.physBytesWritten;
  195.     fprintf(stream, "Bytes written %d+%d remote %d disk %d+%d",
  196.                t1, t2, t3, t4, t5);
  197.     if (t1 + t2 > 0) {
  198.     fprintf(stream, "\ttraffic ratio %%%d",
  199.                (int)((double)(t3+t4+t5)/(double)(t1+t2) * 100.));
  200.     }
  201.  
  202.     if (verbose) {
  203.     /*
  204.      * Print device bytes and zero fills
  205.      */
  206.     t1 = end->gen.deviceBytesWritten - start->gen.deviceBytesWritten;
  207.     t2 = end->gen.deviceBytesRead - start->gen.deviceBytesRead;
  208.     fprintf(stream, "Dev bytes read %d written %d\n", t1, t2);
  209.     t1 = end->blockCache.readZeroFills - start->blockCache.readZeroFills;
  210.     t2 = end->blockCache.writeZeroFills1 -
  211.         start->blockCache.writeZeroFills1;
  212.     t3 = end->blockCache.writeZeroFills2 -
  213.         start->blockCache.writeZeroFills2;
  214.     t4 = end->blockCache.fragZeroFills - start->blockCache.fragZeroFills;
  215.     fprintf(stream, "Zero Fills read %d write1 %d write2 %d frag %d\n",
  216.                    t1, t2, t3, t4);
  217.     t1 = end->blockCache.appendWrites - start->blockCache.appendWrites;
  218.     t2 = end->blockCache.overWrites - start->blockCache.overWrites;
  219.     t3 = end->blockCache.domainReadFails -
  220.         start->blockCache.domainReadFails;
  221.     fprintf(stream, "Appends %d Overwrites %d Failed Reads %d\n",
  222.                    t1, t2, t3);
  223.     }
  224.     t1 = end->blockCache.readAccesses - start->blockCache.readAccesses +
  225.      end->blockCache.fragAccesses - start->blockCache.fragAccesses +
  226.      end->blockCache.fileDescReads - start->blockCache.fileDescReads +
  227.      end->blockCache.indBlockAccesses - start->blockCache.indBlockAccesses +
  228.      end->blockCache.dirBlockAccesses - start->blockCache.dirBlockAccesses;
  229.     t2 = end->blockCache.readHitsOnDirtyBlock -
  230.     start->blockCache.readHitsOnDirtyBlock;
  231.     t3 = end->blockCache.readHitsOnCleanBlock -
  232.     start->blockCache.readHitsOnCleanBlock;
  233.     t4 = end->blockCache.fragHits - start->blockCache.fragHits +
  234.      end->blockCache.fileDescReadHits - start->blockCache.fileDescReadHits +
  235.      end->blockCache.indBlockHits - start->blockCache.indBlockHits +
  236.      end->blockCache.dirBlockHits - start->blockCache.dirBlockHits;
  237.     fprintf(stream, "Cache reads %d hits: dirty %d clean %d other %d",
  238.                t1, t2, t3, t4);
  239.     if (t1 != 0) {
  240.     fprintf(stream, "\thit ratio %%%d",
  241.                (int)((double)(t2+t3+t4)/(double)t1 * 100.));
  242.     }
  243.  
  244.     t1 = end->blockCache.readAheads - start->blockCache.readAheads;
  245.     t2 = end->blockCache.readAheadHits - start->blockCache.readAheadHits;
  246.     t3 = end->blockCache.allInCacheCalls - start->blockCache.allInCacheCalls;
  247.     t4 = end->blockCache.allInCacheTrue - start->blockCache.allInCacheTrue;
  248.     if (t1 > 0) {
  249.     fprintf(stream, "Read Ahead: hits %d/%d all-in-cache %d/%d\n",
  250.             t2, t1, t4, t3);
  251.     }
  252.  
  253.     t1 = end->blockCache.writeAccesses - start->blockCache.writeAccesses +
  254.      end->blockCache.fileDescWrites - start->blockCache.fileDescWrites +
  255.      end->blockCache.indBlockWrites - start->blockCache.indBlockWrites +
  256.      end->blockCache.dirBlockWrites - start->blockCache.dirBlockWrites;
  257.     t2 = end->blockCache.partialWriteHits - start->blockCache.partialWriteHits +
  258.     end->blockCache.fileDescWriteHits - start->blockCache.fileDescWriteHits;
  259.     t3 = end->blockCache.partialWriteMisses -
  260.     start->blockCache.partialWriteMisses;
  261.     t4 = end->blockCache.blocksWrittenThru -
  262.     start->blockCache.blocksWrittenThru;
  263.     fprintf(stream, "Cache writes %d hits %d misses %d thru %d",
  264.                t1, t2, t3, t4);
  265.     if (t1 != 0) {
  266.     fprintf(stream, "\ttraffic ratio %%%d",
  267.                (int)((double)(t3+t4)/(double)t1 * 100.));
  268.     }
  269.  
  270.     fprintf(stream, "Write thru %d data %d indirect %d desc %d dir %d\n",
  271.                t4,
  272.                end->blockCache.dataBlocksWrittenThru -
  273.                start->blockCache.dataBlocksWrittenThru,
  274.                end->blockCache.indBlocksWrittenThru -
  275.                start->blockCache.indBlocksWrittenThru,
  276.                end->blockCache.descBlocksWrittenThru -
  277.                start->blockCache.descBlocksWrittenThru,
  278.                end->blockCache.dirBlocksWrittenThru -
  279.                start->blockCache.dirBlocksWrittenThru);
  280.     if (end->blockCache.fileDescReads > 0) {
  281.     fprintf(stream, "File descriptor reads %d hits %d writes %d hits %d\n",
  282.                    end->blockCache.fileDescReads -
  283.                    start->blockCache.fileDescReads,
  284.                    end->blockCache.fileDescReadHits -
  285.                    start->blockCache.fileDescReadHits,
  286.                    end->blockCache.fileDescWrites -
  287.                    start->blockCache.fileDescWrites,
  288.                    end->blockCache.fileDescWriteHits -
  289.                    start->blockCache.fileDescWriteHits);
  290.     }
  291.     if (end->blockCache.indBlockAccesses > 0) {
  292.     fprintf(stream, "Indirect block reads %d hits %d writes %d\n",
  293.                end->blockCache.indBlockAccesses -
  294.                start->blockCache.indBlockAccesses,
  295.                end->blockCache.indBlockHits -
  296.                start->blockCache.indBlockHits,
  297.                end->blockCache.indBlockWrites -
  298.                start->blockCache.indBlockWrites);
  299.     }
  300.     if (end->blockCache.dirBlockAccesses > 0) {
  301.     fprintf(stream, "Directory block reads %d hits %d writes %d\n",
  302.                    end->blockCache.dirBlockAccesses -
  303.                    start->blockCache.dirBlockAccesses,
  304.                    end->blockCache.dirBlockHits -
  305.                    start->blockCache.dirBlockHits,
  306.                    end->blockCache.dirBlockWrites -
  307.                    start->blockCache.dirBlockWrites);
  308.     }
  309.     if (end->blockCache.vmRequests > 0) {
  310.     fprintf(stream, "VM requests %d tried %d gave %d\n",
  311.                    end->blockCache.vmRequests -
  312.                    start->blockCache.vmRequests,
  313.                    end->blockCache.triedToGiveToVM -
  314.                    start->blockCache.triedToGiveToVM,
  315.                    end->blockCache.vmGotPage -
  316.                    start->blockCache.vmGotPage);
  317.     }
  318.     fprintf(stream, "Cache blocks created %d, alloc from free %d part %d lru %d\n",
  319.                    end->blockCache.unmapped -
  320.                    start->blockCache.unmapped,
  321.                    end->blockCache.totFree -
  322.                    start->blockCache.totFree,
  323.                    end->blockCache.partFree -
  324.                    start->blockCache.partFree,
  325.                    end->blockCache.lru -
  326.                    start->blockCache.lru);
  327.     if (end->alloc.blocksAllocated > 0) {
  328.     fprintf(stream, "Disk blocks alloc %d free %d search %d/%d hash %d\n",
  329.                    end->alloc.blocksAllocated -
  330.                    start->alloc.blocksAllocated,
  331.                    end->alloc.blocksFreed -
  332.                    start->alloc.blocksFreed,
  333.                    end->alloc.cylsSearched -
  334.                    start->alloc.cylsSearched,
  335.                    end->alloc.cylBitmapSearches -
  336.                    start->alloc.cylBitmapSearches,
  337.                    end->alloc.cylHashes -
  338.                    start->alloc.cylHashes);
  339.     fprintf(stream, "Fragments alloc %d free %d upgrade %d blocks made %d used %d, bad hints %d\n",
  340.                    end->alloc.fragsAllocated -
  341.                    start->alloc.fragsAllocated,
  342.                    end->alloc.fragsFreed -
  343.                    start->alloc.fragsFreed,
  344.                    end->alloc.fragUpgrades -
  345.                    start->alloc.fragUpgrades,
  346.                    end->alloc.fragToBlock -
  347.                    start->alloc.fragToBlock,
  348.                    end->alloc.fullBlockFrags -
  349.                    start->alloc.fullBlockFrags,
  350.                    end->alloc.badFragList -
  351.                    start->alloc.badFragList);
  352.     }
  353.     if (end->nameCache.accesses > 0) {
  354.     fprintf(stream, "Name cache entries %d accesses %d hits %d replaced %d\n",
  355.                end->nameCache.size,
  356.                end->nameCache.accesses -
  357.                start->nameCache.accesses,
  358.                end->nameCache.hits -
  359.                start->nameCache.hits,
  360.                end->nameCache.replacements -
  361.                start->nameCache.replacements);
  362.     }
  363.     fprintf(stream, "Handles %d created %d installed %d hits %d old %d version %d flush %d\n",
  364.                end->handle.exists,
  365.                end->handle.created -
  366.                start->handle.created,
  367.                end->handle.installCalls -
  368.                start->handle.installCalls,
  369.                end->handle.installHits -
  370.                start->handle.installHits,
  371.                end->handle.oldHandles -
  372.                start->handle.oldHandles,
  373.                end->handle.versionMismatch -
  374.                start->handle.versionMismatch,
  375.                end->handle.cacheFlushes -
  376.                start->handle.cacheFlushes);
  377.     fprintf(stream, "\tfetched %d hits %d released %d locks %d/%d wait %d\n",
  378.                end->handle.fetchCalls -
  379.                start->handle.fetchCalls,
  380.                end->handle.fetchHits -
  381.                start->handle.fetchHits,
  382.                end->handle.releaseCalls -
  383.                start->handle.releaseCalls,
  384.                end->handle.lockCalls -
  385.                start->handle.lockCalls,
  386.                end->handle.locks -
  387.                start->handle.locks,
  388.                end->handle.lockWaits -
  389.                start->handle.lockWaits);
  390.     fprintf(stream, "Segments fetched %d hits %d\n",
  391.                end->handle.segmentFetches -
  392.                start->handle.segmentFetches,
  393.                end->handle.segmentHits -
  394.                start->handle.segmentHits);
  395.     fprintf(stream, "Lookup relative %d absolute %d redirect %d found %d loops %d timeouts %d stale %d\n",
  396.                end->prefix.relative -
  397.                start->prefix.relative,
  398.                end->prefix.absolute -
  399.                start->prefix.absolute,
  400.                end->prefix.redirects -
  401.                start->prefix.redirects,
  402.                end->prefix.found -
  403.                start->prefix.found,
  404.                end->prefix.loops -
  405.                start->prefix.loops,
  406.                end->prefix.timeouts -
  407.                start->prefix.timeouts,
  408.                end->prefix.stale -
  409.                start->prefix.stale);
  410. }
  411.  
  412.  
  413. /*
  414.  *----------------------------------------------------------------------
  415.  *
  416.  * PrintVmStats --
  417.  *
  418.  *    Print out VM statistics.  If both a start and end
  419.  *    sample of the statistics are given then the differences between
  420.  *    the two are printed.  To just print the total cumulative statistics
  421.  *    from one sample, specify a single VmStats buffer with the 'end'
  422.  *    parameter.
  423.  *
  424.  * Results:
  425.  *    None.
  426.  *
  427.  * Side effects:
  428.  *    Prints to the specified stream
  429.  *
  430.  *----------------------------------------------------------------------
  431.  */
  432. void
  433. PrintVmStats(stream, start, end)
  434.     FILE *stream;    /* Output stream */
  435.     Vm_Stat *start;    /* 0, or address of "before run" statistics */
  436.     Vm_Stat *end;    /* End of run statistics */
  437. {
  438.     register    int    *diffPtr;
  439.     register    int    *startPtr;
  440.     register    int    *endPtr;
  441.     int            i;
  442.     int            inusePages;
  443.     int            totPages;
  444.     int            numModifiedPages;
  445.     Vm_Stat        diffStat;
  446.     int            totPercent;
  447.     int            totFaults;
  448.     int            heapPercent;
  449.     int            stkPercent;
  450.     int            quickPercent;    
  451.     int            totHits;
  452.     int            totPrefetches;
  453.     int            hitPct;
  454.  
  455.     startPtr = (int *)start;
  456.     endPtr = (int *)end;
  457.     diffPtr = (int *)&diffStat;
  458.  
  459.     for (i = 0; 
  460.          i < sizeof(Vm_Stat) / sizeof(int); 
  461.      i++, startPtr++, endPtr++, diffPtr++) {
  462.     *diffPtr = *endPtr - *startPtr;
  463.     }
  464.  
  465.     (void)Vm_Cmd(VM_COUNT_DIRTY_PAGES, &numModifiedPages);
  466.     fprintf(stream, "Kernel VM Pages: %d (Code+Data=%d Stacks=%d)\n",
  467.          end->kernMemPages + end->kernStackPages,
  468.          end->kernMemPages, end->kernStackPages);
  469.     inusePages = end->numDirtyPages + end->numUserPages;
  470.     totPages = end->numFreePages + inusePages;
  471.     fprintf(stream, "User VM Pages:   %d (Free=%d Dirty=%d Res=%d Alloc-list=%d)\n",
  472.         end->numFreePages + end->numDirtyPages + 
  473.         end->numReservePages + end->numUserPages, 
  474.         end->numFreePages, end->numDirtyPages,
  475.         end->numReservePages,
  476.         end->numUserPages);
  477.     fprintf(stream, "Modified pages: Total=%d %%Tot-dirty=%0.2f %%Inuse-dirty=%0.2f\n",
  478.         numModifiedPages,
  479.         (float) (numModifiedPages) / (float)totPages * 100.0,
  480.         (float) (numModifiedPages) / (float)inusePages * 100.0);
  481.     fprintf(stream, "FS Pages: Current=%d Max=%d Min=%d\n", 
  482.         end->fsMap - end->fsUnmap, end->maxFSPages, end->minFSPages);
  483.     fprintf(stream,
  484.          "Faults: %8d (Zero=%d FS=%d Swap=%d Quick=%d Coll=%d)\n", 
  485.          diffStat.totalFaults, diffStat.zeroFilled, diffStat.fsFilled,
  486.          diffStat.psFilled,diffStat.quickFaults, diffStat.collFaults);
  487.     fprintf(stream, "        %8d (Code=%d Heap=%d Stack=%d)\n", 
  488.          diffStat.totalFaults, diffStat.codeFaults, diffStat.heapFaults,
  489.          diffStat.stackFaults);
  490.     fprintf(stream, 
  491.         "Mod page stats:  Pot-mod=%d Not-mod=%d Not-hard-mod=%d\n",
  492.         diffStat.potModPages, diffStat.notModPages, 
  493.         diffStat.notHardModPages);
  494.  
  495.     /*
  496.      * Copy on write. 
  497.      */
  498.     totPages = diffStat.numCOWStkPages + diffStat.numCOWHeapPages;
  499.     totFaults = diffStat.numCOWStkFaults + diffStat.numCOWHeapFaults;
  500.     if (diffStat.numCOWHeapPages > 0) {
  501.     heapPercent = 100.0 * ((float)diffStat.numCOWHeapFaults / 
  502.                       diffStat.numCOWHeapPages);
  503.     } else {
  504.     heapPercent = 0;
  505.     }
  506.     if (diffStat.numCOWStkPages > 0) {
  507.     stkPercent = 100.0 * ((float)diffStat.numCOWStkFaults / 
  508.                       diffStat.numCOWStkPages);
  509.     } else {
  510.     stkPercent = 0;
  511.     }
  512.     if (totPages > 0) {
  513.     totPercent = 100.0 * ((float)totFaults / totPages);
  514.     } else {
  515.     totPercent = 0;
  516.     }
  517.     if (totFaults > 0) {
  518.     quickPercent = 100.0 * ((float)diffStat.quickCOWFaults / totFaults);
  519.     } else {
  520.     quickPercent = 0;
  521.     }
  522.     fprintf(stream, 
  523.         "COW: Heap (%d/%d)=%d%% Stk (%d/%d)=%d%% Tot (%d/%d)=%d%%\n",
  524.         diffStat.numCOWHeapFaults, diffStat.numCOWHeapPages, heapPercent,
  525.         diffStat.numCOWStkFaults, diffStat.numCOWStkPages, stkPercent,
  526.         totFaults, totPages, totPercent);
  527.     fprintf(stream, "     Quick (%d/%d)=%d%%\n",
  528.         diffStat.quickCOWFaults, totFaults, quickPercent);
  529.     /*
  530.      * Copy on reference.
  531.      */
  532.     totPages = diffStat.numCORStkPages + diffStat.numCORHeapPages;
  533.     totFaults = diffStat.numCORStkFaults + diffStat.numCORHeapFaults;
  534.     if (diffStat.numCORHeapPages > 0) {
  535.     heapPercent = 100.0 * ((float)diffStat.numCORHeapFaults / 
  536.                       diffStat.numCORHeapPages);
  537.     } else {
  538.     heapPercent = 0;
  539.     }
  540.     if (diffStat.numCORStkPages > 0) {
  541.     stkPercent = 100.0 * ((float)diffStat.numCORStkFaults / 
  542.                       diffStat.numCORStkPages);
  543.     } else {
  544.     stkPercent = 0;
  545.     }
  546.     if (totPages > 0) {
  547.     totPercent = 100.0 * ((float)totFaults / totPages);
  548.     } else {
  549.     totPercent = 0;
  550.     }
  551.     fprintf(stream,
  552.             "COR: Heap (%d/%d)=%d%% Stk (%d/%d)=%d%% Tot (%d/%d)=%d%%\n",
  553.         diffStat.numCORHeapFaults, diffStat.numCORHeapPages, heapPercent,
  554.         diffStat.numCORStkFaults, diffStat.numCORStkPages, stkPercent,
  555.         totFaults, totPages, totPercent);
  556.     totPages = diffStat.numCORStkFaults + diffStat.numCORHeapFaults;
  557.     totFaults = diffStat.numCORCOWStkFaults + diffStat.numCORCOWHeapFaults;
  558.     if (diffStat.numCORCOWHeapFaults > 0) {
  559.     heapPercent = 100.0 * ((float)diffStat.numCORCOWHeapFaults / 
  560.                       diffStat.numCORHeapFaults);
  561.     } else {
  562.     heapPercent = 0;
  563.     }
  564.     if (diffStat.numCORCOWStkFaults > 0) {
  565.     stkPercent = 100.0 * ((float)diffStat.numCORCOWStkFaults / 
  566.                       diffStat.numCORStkFaults);
  567.     } else {
  568.     stkPercent = 0;
  569.     }
  570.     if (totPages > 0) {
  571.     totPercent = 100.0 * ((float)totFaults / totPages);
  572.     } else {
  573.     totPercent = 0;
  574.     }
  575.     fprintf(stream,
  576.             "COR-mod: Heap(%d/%d)=%d%% Stk (%d/%d)=%d%% Tot (%d/%d)=%d%%\n",
  577.         diffStat.numCORCOWHeapFaults, diffStat.numCORHeapFaults,heapPercent,
  578.         diffStat.numCORCOWStkFaults, diffStat.numCORStkFaults, stkPercent,
  579.         diffStat.numCORCOWHeapFaults + diffStat.numCORCOWStkFaults,
  580.         diffStat.numCORHeapFaults + diffStat.numCORStkFaults, totPercent);
  581.  
  582.     fprintf(stream, "Swap pages copied: %d\n", diffStat.swapPagesCopied);
  583.     fprintf(stream,
  584.              "Vm allocs: %d (Free=%d From-FS=%d From-alloc-list=%d)\n",
  585.          diffStat.numAllocs, diffStat.gotFreePage, diffStat.gotPageFromFS, 
  586.          diffStat.pageAllocs);
  587.     fprintf(stream, 
  588.          "VM-FS stats: Asked=%d Free-pages=%d Allocs=%d Frees=%d\n",
  589.          diffStat.fsAsked, diffStat.haveFreePage, diffStat.fsMap, 
  590.          diffStat.fsUnmap);
  591.     fprintf(stream, "Alloc-list searches: %d (Free=%d In-use=%d)\n",
  592.          diffStat.numListSearches, diffStat.usedFreePage, 
  593.          diffStat.numListSearches - diffStat.usedFreePage);
  594.     fprintf(stream, "Extra-searches: %d (Lock=%d Ref=%d Dirty=%d)\n",
  595.          diffStat.lockSearched + diffStat.refSearched + 
  596.          diffStat.dirtySearched,
  597.          diffStat.lockSearched, diffStat.refSearched, 
  598.          diffStat.dirtySearched);
  599.     fprintf(stream, "Pages written %d\n", diffStat.pagesWritten);
  600.  
  601.     totPrefetches = diffStat.codePrefetches + diffStat.heapFSPrefetches +
  602.             diffStat.heapSwapPrefetches + diffStat.stackPrefetches;
  603.     if (totPrefetches > 0) {
  604.     totHits = diffStat.codePrefetchHits + diffStat.heapFSPrefetchHits +
  605.           diffStat.heapSwapPrefetchHits + diffStat.stackPrefetchHits;
  606.     fprintf(stream, "Prefetch stats:\n");
  607.     if (diffStat.codePrefetches > 0) {
  608.         hitPct = 100 * ((float)diffStat.codePrefetchHits / 
  609.                 (float)diffStat.codePrefetches);
  610.         fprintf(stream, "    code (%d/%d)=%d%%\n",
  611.             diffStat.codePrefetchHits, diffStat.codePrefetches, hitPct);
  612.     }
  613.     if (diffStat.heapFSPrefetches > 0) {
  614.         hitPct = 100 * ((float)diffStat.heapFSPrefetchHits / 
  615.                 (float)diffStat.heapFSPrefetches);
  616.         fprintf(stream, "    heap-fs (%d/%d)=%d%%\n",
  617.         diffStat.heapFSPrefetchHits, diffStat.heapFSPrefetches, hitPct);
  618.     }
  619.     if (diffStat.heapSwapPrefetches > 0) {
  620.         hitPct = 100 * ((float)diffStat.heapSwapPrefetchHits / 
  621.                 (float)diffStat.heapSwapPrefetches);
  622.         fprintf(stream, "    heap-swp (%d/%d)=%d%%\n",
  623.         diffStat.heapSwapPrefetchHits, diffStat.heapSwapPrefetches, 
  624.         hitPct);
  625.     }
  626.     if (diffStat.stackPrefetches > 0) {
  627.         hitPct = 100 * ((float)diffStat.stackPrefetchHits / 
  628.                 (float)diffStat.stackPrefetches);
  629.         fprintf(stream, "    stack (%d/%d)=%d%%\n",
  630.         diffStat.stackPrefetchHits, diffStat.stackPrefetches, hitPct);
  631.     }
  632.     hitPct = 100 * ((float)totHits / (float)totPrefetches);
  633.     fprintf(stream, "    total (%d/%d)=%d%%\n",
  634.         totHits, totPrefetches, hitPct);
  635.     fprintf(stream, "    aborts=   %d\n", diffStat.prefetchAborts);
  636.     }
  637.  
  638.     fprintf(stream, "Contexts stolen %d pmegs stolen %d\n",
  639.          diffStat.machDepStat.stealContext, diffStat.machDepStat.stealPmeg);
  640. }
  641.